home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Invert.c - A simple screen fader that runs as a MultiFinder
- application. Is typically launched by Lunarmobiscuit's
- Darkness MultiFinder screen saver program.
-
- copyright © 1989 by Tom Dowdy
- All rights reserved
-
- Modifications
- Aug 5 1989 TED basic fade working as standalone code
- Nov 30 1989 TED file converted to a standalone application
-
- This is about as simple as a screen blackout can get. Not very useful,
- but a good starting point for creating your own screen saver.
-
- */
-
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <Memory.h>
- #include <Dialogs.h>
- #include <Resources.h>
-
-
- typedef struct
- {
- Boolean isResource; // are these settings from a resource?
- Boolean doInvert; // do we invert on fade?
- } SettingsRecord, *SettingsPtr, **SettingsHandle;
-
- typedef struct
- {
- SettingsHandle theSettings; // what options could someone want?
- Rect maxRect; // Size of the fading area
- } BlackoutRecord, *BlackoutPtr, **BlackoutHandle;
-
-
- #include "Blackout.h"
-
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Initialize
-
- // FORWARD DECALARES, DoSetupDialog MUST be first for entry point
-
- SettingsHandle GetSettings();
- void WriteSettings(SettingsHandle theSettings);
-
- void DoSetupDialog(SetupParamBlock *theSetup)
- {
- short hit;
- DialogPtr dPtr;
- SettingsHandle theSettings;
-
- CenterWindow('DLOG', kSetupDialogID, nil);
- dPtr = GetNewDialog(kSetupDialogID, nil, (WindowPtr)-1);
- if (dPtr != nil)
- {
- SetPort(dPtr);
- SetUserItem (dPtr, 3, DefaultUserItem);
- SetUserItem (dPtr, 6, AboutUserItem);
- theSettings = GetSettings();
- if (theSettings != nil)
- SetItemCtlValue(dPtr, 5, (**theSettings).doInvert);
-
- ShowWindow(dPtr);
- do
- {
- ModalDialog((ModalFilterProcPtr) OKCancelFilterProc, &hit);
- if (hit == 5)
- SetItemCtlValue(dPtr, 5, !GetItemCtlValue(dPtr, 5));
- }
- while ((hit != ok) && (hit != cancel));
-
- if ((hit == ok) && (theSettings != nil))
- {
- hit = GetItemCtlValue(dPtr, 5);
- (**theSettings).doInvert = hit;
-
- WriteSettings(theSettings);
- }
-
- DisposDialog(dPtr);
- }
-
- } // DoSetupDialog
-
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Initialize
-
- SettingsHandle GetSettings()
- {
- SettingsHandle aSetup;
-
- aSetup = (SettingsHandle) Get1Resource(kSettingsType, kSettingsID);
- if (aSetup == nil)
- {
- aSetup = (SettingsHandle)NewHandle(sizeof(SettingsRecord));
- if (aSetup != nil)
- {
- (**aSetup).isResource = false;
- (**aSetup).doInvert = false;
- }
- }
- else
- {
- (**aSetup).isResource = true;
- }
-
- return(aSetup);
-
- } // GetSettings
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Initialize
-
- void WriteSettings(SettingsHandle theSettings)
- {
- Str255 aString;
-
- if (theSettings == nil)
- return;
-
- if ((**theSettings).isResource)
- {
- ChangedResource((Handle) theSettings);
- WriteResource((Handle) theSettings);
- }
- else
- {
- aString[0] = 0;
- AddResource((Handle) theSettings, kSettingsType, kSettingsID, aString);
- WriteResource((Handle) theSettings);
- }
-
- } // WriteSettings
-
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Initialize
-
- BlackoutHandle PreflightBlackout(
- long * minSleepTime,
- long * maxSleepTime)
- {
-
- BlackoutHandle theBlackout;
-
- /* Create our new Blackout's state information */
- theBlackout = (BlackoutHandle)NewHandle(sizeof(BlackoutRecord));
-
- /* Inform the application of our desired sleepTime */
- *minSleepTime = 30;
- *maxSleepTime = 30;
-
- /* Return the created Blackout */
- return(theBlackout);
-
- } // PreflightBlackout
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Initialize
-
- Boolean InitBlackout(
- BlackoutHandle theBlackout, // context storage
- WindowPtr blackoutWindow) // window to Blackout into
- /*
- Routine should allocate and return any storage it needs for state
- information. NIL if none is needed.
-
- In addition, the sleepTime parameter should be changed to the value which will
- be passed for the sleep parameter to WaitNextEvent.
-
- return true if this function should continue, false if the fader
- should stop right now.
- */
- {
- SettingsHandle theSettings;
-
- /* Store away any useful information we need */
- if (theBlackout != nil)
- {
- (**theBlackout).maxRect = blackoutWindow->portRect;
- theSettings = GetSettings();
- (**theBlackout).theSettings = theSettings;
-
- PaintRect(&blackoutWindow->portRect);
- }
-
-
- return(true);
-
- } // InitBlackout
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Terminate
-
- void DisposeBlackout(BlackoutHandle theBlackout)
- /*
- Routine should dispose of any storage which was created and do any final
- cleanup before the window is disposed of.
- */
- {
- if (theBlackout != nil)
- DisposHandle((Handle) theBlackout);
-
- } // DisposeBlackout
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Main
-
- Boolean BlackoutEvent(EventRecord *theEvent)
- /*
- Return false to let the shell handle the event
- */
- {
- #pragma unused (theEvent)
-
- return(false);
-
- } // BlackoutEvent
-
- /* ------------------------------------------------------------------------------------ */
- #pragma segment Main
-
- void BlackoutIdle(WindowPtr blackoutWindow, BlackoutHandle theBlackout)
- /*
- Called to idle the Blackout effect. Do something creative here.
- */
- {
- #pragma unused (blackoutWindow)
-
- Rect theRect;
-
- if (theBlackout == nil)
- return;
-
- if ((**theBlackout).theSettings == nil)
- return;
-
- if ( (**(**theBlackout).theSettings).doInvert)
- {
- theRect = (**theBlackout).maxRect;
- InvertRect(&theRect);
- }
-
- } // BlackoutIdle
-
-